/* 项目相关 */
import request from '@/utils/request.js'
import { getFilename } from '@/utils/index'
/**
 * 创建项目
 * @param {String}  name
 * @param {String}  avatarUrl
 * @param {Number}  compId 比赛外键
 * @param {String}  compName 比赛名
 * @param {Number}  awardLevel 获奖等级
 * @param {String}  tags
 * @param {Date}  awardTime 获奖时间
 * @param {String}  awardProveUrl
 * @param {String}  intro
 * @param {Boolean}  isAnonymous 是否为匿名资源
 */
export const postCompProject = (data) => request('/project', 'POST', data)

/**
 * 获取推荐项目粗略信息表
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {String}  sortBy 排序字段
 * @param {String}  orderBy 排序方式
 */
export const getRecommendProject = (params) => request('/recommend', 'GET', params)

/**
 * 获取所有项目粗略信息表
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  userId 根据用户ID筛选
 * @param {Number}  compId 根据比赛ID筛选
 * @param {Number}  awardLevel 根据获奖等级筛选
 * @param {String}  sortBy 排序字段
 * @param {String}  orderBy 排序方式
 */
export const getProjects = (params) => request('/project', 'GET', params)

/**
 * 获取个人项目列表
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  compId 根据比赛ID筛选
 * @param {Number}  awardLevel 根据获奖等级筛选
 * @param {String}  sortBy 排序字段
 * @param {String}  orderBy 排序方式
 */
export const getMyCompProjects = (params) => request('/project/me', 'GET', params)

/**
 * 获取项目详细信息
 * @param {Number}  projectId
 */
export const getProject = (projectId) => request(`/project/${ projectId }`, 'GET', {})

/**
 * 更新项目详细信息
 * @param {Number}  projectId
 * @param {String}  name
 * @param {String}  avatarUrl
 * @param {Number}  compId 比赛外键
 * @param {String}  compName 比赛名
 * @param {Number}  awardLevel 获奖等级
 * @param {String}  tags
 * @param {Date}  awardTime 获奖时间
 * @param {String}  awardProveUrl
 * @param {String}  intro
 */
export const putCompProject = (projectId, data) => request(`/project/${ projectId }`, 'PUT', data)

/**
 * 删除项目
 * @param {Number}  projectId
 */
export const deleteCompProject = (projectId) => request(`/project/${ projectId }`, 'DELETE', {})

/**
 * 获取个人项目列表
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  projectId
 */
export const getProjectComments = (params) => request(`/project/resource/score`, 'GET', params)

/**
 * 发布评论
 * @param {Number}  resourceId 附件ID
 * @param {Number} score 评分
 * @param {String}  comment 内容
 */
export const postRemark = (resourceId, data) => request(`/project/resource/score/${ resourceId }`, 'POST', data)

/**
 * 删除评价
 * @param {Number}  commentId
 */
export const deleteComment = (commentId) => request(`/project/resource/score/${ commentId }`, 'DELETE')

/**
 * 获取公开评论
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  projectId
 */
export const getPublicComments = (params) => request(`/project/discuss/${ params.projectId }`, 'GET', params)

/**
 * 新建公开评论
 * @param {Number}  projectId 项目ID
 * @param {String}  comment 内容
 */
export const postPublicComment = (data) => request(`/project/discuss`, 'POST', data)

/**
 * 删除公开评论
 * @param {Number}  commentId
 */
export const deletePublicComment = (commentId) => request(`/project/discuss/${ commentId }`, 'DELETE')

/**
 * 判断是否收藏
 * @param {Number}  projectId
 */
export const isCollected = (projectId) => request(`/project/collection/check/${ projectId }`, 'GET')

/**
 * 收藏项目
 * @param {Number}  projectId
 */
export const collectProject = (projectId) => request(`/project/collection/${ projectId }`, 'POST')

/**
 * 取消收藏项目
 * @param {Number}  projectId
 */
export const cancelCollectProject = (projectId) => request(`/project/collection/${ projectId }`, 'DELETE')

/**
 * 获取比赛项目所有资源信息
 * @param {Number}  id 项目id
 * @param {Boolean}  edit 是否处于编辑模式（项目管理员专属)
 */
export const getCompResources = ({ id, edit }) => request(`/project/${ id }/resources?edit=${ edit }`, 'GET')

/**
 * 获取上传文件签名
 * @param {Number}  projectId
 * @param {String}  filename
 */
export const getFilesSignature = (projectId, filename) => request(`/project/${ projectId }/resources/sign/upload/private?filename=${ getFilename(filename) }`, 'GET')

/**
 * 创建一条项目附件信息
 * @param {Number}  projectId
 * @param {String}  name 文件名
 * @param {Number}  fileType 参考fileClassify里的value
 * @param {String}  filename 保存在oss里的资源文件名(包括前缀)
 * @param {Number}  price aha币定价
 */
export const postResource = (projectId, data) => request(`/project/resource/${ projectId }`, 'POST', data)

/**
 * 删除资源
 * @param {Number}  resourceId
 */
export const deleteResource = (resourceId) => request(`/project/resource/${ resourceId }`, 'DELETE', {})

/**
 * 修改资源信息
 * @param {Number}  resourceId
 * @param {String}  name
 * @param {Number}  fileType 参考garr_fileClassify
 * @param {String}  filename 保存在oss里的资源文件名(包括前缀)
 * @param {Number}  price
 */
export const putResource = (resourceId, data) => request(`/project/resource/${ resourceId }`, 'PUT', data)

/**
 * 获取下载签名
 * @param {Number}  resourceId
 */
export const getLoadSignature = (resourceId) => request(`/project/resource/${ resourceId }/sign/download`, 'GET')

/**
 * 获取阅读签名
 * @param {Number}  resourceId
 */
export const getReadSignature = (resourceId) => request(`/project/resource/${ resourceId }/sign/read`, 'GET')

/**
 * 创建项目成员
 * @param {Number}  projectId
 * @param {Number}  memberUserId 成员ID
 * @param {Number}  rank 排名
 * @param {String}  job 职务
 * @param {Boolean}  editable 是否可编辑项目信息
 */
export const postMember = ({ projectId, ...data }) => request(`/project/member/${ projectId }`, 'POST', data)

/**
 * 更新项目单个成员信息
 * @param {Number}  projectId
 * @param {Number}  userId 成员ID
 * @param {Number}  rank 排名
 * @param {String}  job 职务
 * @param {Boolean}  editable 是否可编辑项目信息
 */
export const putMember = ({ projectId, userId, ...data }) => request(`/project/member/${ projectId }/${ userId }`, 'PUT', data)

/**
 * 批量更新项目成员
 * @param {Number}  projectId
 * @param {Array}  body 内容同上
 */
export const putMembers = ({ projectId, members }) => request(`/project/members/${ projectId }`, 'PUT', members)

/**
 * 删除成员
 * @param {Number}  projectId
 * @param {Number}  userId 成员ID
 */
export const deleteMember = ({ projectId, userId }) => request(`/project/member/${ projectId }/${ userId }`, 'DELETE')

/**
 * 获取个人收藏的课程设计
 * @param {Number} pageNum
 * @param {Number} pageSize
 * @param {String} courseDesignName
 */
export const getCollectedCourseDesign = (params) => request(`/courseDesign/collection`, 'GET', params)
/**
 * 获取个人收藏的竞赛项目
 * @param {Number} pageNum
 * @param {Number} pageSize
 * @param {String} projectName
 */
export const getCollectedCompProject = (params) => request(`/project/collection`, 'GET', params)

/**
 * 分页获取个人的课设项目
 * @param {Number} pageNum
 * @param {Number} pageSize
 */
export const getMyCourseDesign = (param) => request(`/courseDesign/me`, 'GET', param)

/**
 * 创建课设项目
 * @param {String}  cdName
 * @param {String}  cdAvatarUrl
 * @param {Number}  cdCourseId 课程id
 * @param {String}  cdTags 课设标签
 * @param {Number}  cdIntro 介绍
 */
export const postCourseDesign = (data) => request(`/courseDesign`, 'POST', data)

/**
 * 更新课设项目
 * @param {Number}  courseDesignId 课设id
 * @param {String}  cdName
 * @param {String}  cdAvatarUrl
 * @param {Number}  cdCourseId 课程id
 * @param {String}  cdTags 课设标签
 * @param {Number}  cdIntro 介绍
 */
export const putCourseDesign = (courseDesignId, data) => request(`/courseDesign/${ courseDesignId }`, 'PUT', data)

/**
 * 删除课设项目
 * @param {Number} courseDesignId
 */
export const delCourseDesign = (courseDesignId) => request(`/courseDesign/${ courseDesignId }`, 'DELETE')

/**
 * 根据项目id获取所有项目成员
 * @param {Number} projectId
 */
export const getProjectMembers = (projectId) => request(`/project/${ projectId }/members`, 'GET')

/**
 * 获取所有课设
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 * @param {Number}  userId 根据用户ID筛选
 * @param {Number}  cId 根据课程ID筛选
 * @param {Number}  cType 课程类型
 * @param {String}  sortBy 排序字段
 * @param {String}  orderBy 排序方式
 */
export const getCourseDesigns = (params) => request(`/courseDesign`, 'GET', params)

/**
 * 根据id获取课设
 * @param {Number} courseDesignId
 */
export const getCourseDesign = (courseDesignId) => request(`/courseDesign/${ courseDesignId }`, 'GET')

/**
 * 获取课设项目的附件
 * @param {Number}  id 项目id
 * @param {Boolean} edit 是否获取未审核过的
 */
export const getCourseResources = ({ id, edit = true }) => request(`/courseDesign/${ id }/resources?edit=${ edit }`, 'GET')

/**
 * 获取课设项目上传签名
 * @param {Number}  courseDesignId
 * @param {String}  filename
 */
export const getCourseFileSign = (courseDesignId, filename) => request(`/courseDesign/${ courseDesignId }/resources/sign/upload/private?filename=${ getFilename(filename) }`, 'GET')

/**
 * 判断课设是否收藏
 */
export const isCollectedCourseDesign = (id) => request(`/courseDesign/collection/check/${ id }`, 'GET')
/**
 * 收藏课设
 */
export const collectCourseDesign = (id) => request(`/courseDesign/collection/${ id }`, 'POST')
/**
 * 取消收藏课设
 */
export const CancelCollectCourseDesign = (id) => request(`/courseDesign/collection/${ id }`, 'DELETE')

/**
 * 全文检索项目, 模糊搜索项目
 * @param {String} targetType 项目类型，competition/courseDesign
 * @param {String}  searchKey 关键词
 * @param {Number}  awardLevel 获奖等级
 * @param {Number}  targetCompetitionId 竞赛id
 * @param {Number}  courseTypeId 课程类型
 * @param {String}  sortCode 排序字段：read点击量，collect收藏量，time时间
 * @param {Number}  modChoiceCode 排序方式：0 升序，1降序
 * @param {Number}  pageNum
 * @param {Number}  pageSize
 */
export const getSearchProjects = (params) => request(`/searchList`, 'GET', params)

/**
 * 根据获奖等级和文件分类获取参考价格
 */
export const getFilePrice = ({ awardLevel, classifyId }) => request(`/project/resource/purchased/getPrice/${ awardLevel }/${ classifyId }`, 'GET')

/**
 * 根据项目id，获取当前用户在该项目中支付情况
 */
export const getProjectPayoutStatus = (projectId) => request(`/project/getPayInfo/${ projectId }`, 'GET')

